﻿using System;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using DashboardModule.Controllers;
using DashboardModule.Services.Temp;
using TimeSplicerModule.Services;
using TimeSplicerModule.Factories;

namespace DashboardModule
{
    public class DashboardModule : IModule
    {
        private readonly IRegionManager _regionManager;
        private readonly IUnityContainer _container;
        private readonly IUserService _userService;
        private readonly IProjectService _projectService;
        private readonly IProjectFactory _projectFactory;
        private readonly ITaskService _taskService;
        private readonly ITaskFactory _taskFactory;
        private readonly IStatusFactory _statusFactory;
        private readonly ICategoryFactory _categoryFactory;
        private readonly IProjectUserFactory _projectUserFactory;

        // todo: try and inject timesplicer module items here
        public DashboardModule(IRegionManager regionManager, IUnityContainer container, IUserService userSerivce, IProjectService projectService, IProjectFactory projectFactory,
            ITaskService taskService, ITaskFactory taskFactory, IStatusFactory statusFactory, ICategoryFactory categoryFactory, IProjectUserFactory projectUserFactory)
        {
            _regionManager = regionManager;
            _container = container;
            _userService = userSerivce;
            _projectService = projectService;
            _projectFactory = projectFactory;
            _taskService = taskService;
            _taskFactory = taskFactory;
            _statusFactory = statusFactory;
            _categoryFactory = categoryFactory;
            _projectUserFactory = projectUserFactory;
        }

        public void Initialize()
        {
            // register views
            _container.RegisterType<Object, Views.TempReportsView>(typeof(Views.TempReportsView).Name);

            // register controllers
            _container.RegisterInstance<ITempReportsViewController>(new TempReportsViewController());

            // register services
            var tempService = new TempReportsService(_container, _userService, _projectService, _projectFactory, _taskService, _taskFactory, _statusFactory, _categoryFactory, _projectUserFactory);

            _container.RegisterInstance<ITempReportsService>(tempService);
        }
    }
}
